﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace EFCoreBooks
{
  internal class MyDbContextDesignTimeFactory : IDesignTimeDbContextFactory<MyDbContext>
  {
    /// <summary>
    /// 开发时运行（Add-Migration Update-Database等） 项目正式运行时不会用这个类
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public MyDbContext CreateDbContext(string[] args)
    {
      DbContextOptionsBuilder<MyDbContext> builder = new DbContextOptionsBuilder<MyDbContext>();
      var str = @"Data Source=(localdb)\ProjectModels;Initial Catalog=demo1;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False";
     // var str = @"Data Source=(localdb)\\ProjectModels;Initial Catalog=demo1;Integrated Security=True;Connect Timeout=5;Encrypt=False;";
      //Environment.GetEnvironmentVariable("connStr");
      builder.UseSqlServer(str);
      MyDbContext ctx = new MyDbContext(builder.Options);
      return ctx;
    }
  }
}
